package com.buaa.aiguangxi.controller;

import com.buaa.aiguangxi.pojo.User;
import com.buaa.aiguangxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/entry/login")
    public void userLogin(@RequestParam("username")String username,@RequestParam("password")String password){
    }
    @ResponseBody
    @PostMapping("/register")
    public Map<String ,Object > register(@RequestParam("username")String username,@RequestParam("password")String password){
        Map<String,Object> map=new HashMap<>();
        User user=new User();
        user.setUsername(username);
        user.setUserPassword(password);
        if (userService.getUserByName(username)!=null){
            map.put("msg","-1");
            map.put("description","用户名已被使用！");
            return map;
        }
        int userid=userService.addUser(user);
        map.put("msg","200");
        map.put("description","注册成功！");
        return map;
    }
    @ResponseBody
    @PostMapping("/entry/logout")
    public Map<String,Object> logout(){
        Map<String,Object> map=new HashMap<>();
        map.put("success",true);
        map.put("msg","");
        return map;
    }
}
